/**
 * datatype扩展
 */
$.Datatype.need1 = function (gets, obj, curform, regxp) {
    var need = 1, numselected = curform.find("input[name='" + obj.attr("name") + "']:checked").length;
    return numselected >= need ? true : "请至少选择" + need + "项！";
};
$.Datatype.need2 = function (gets, obj, curform, regxp) {
    var need = 2, numselected = curform.find("input[name='" + obj.attr("name") + "']:checked").length;
    return numselected >= need ? true : "请至少选择" + need + "项！";
};
$.Datatype.d = /^(\d*\.)?\d+$/;

//update-start--Author:zhangguoming  Date:20140826 for：添加 下拉框、combotree 验证
$.Datatype.select1 = function (gets, obj, curform, regxp) {
    var name = obj.attr("name") != undefined ? "name" : "comboname"; // select 或 combotree
    var need = 1, numselected = curform.find("select[" + name + "='" + obj.attr(name) + "'] option[selected='selected']").length;
    // update by xiu 160601
    if (name == "comboname") {//如果是combotree
        var objVal = curform.find("input[name='" + obj.attr(name) + "']").val();
        //如果没有找到隐藏域 选中数为0，如果找到隐藏域 取隐藏域的值（多选时值用 ， 拼接）
        objVal = objVal == undefined ? 0 : objVal;
        //如果找到了隐藏域并且有值， 选中的项目长度即为 按，分割的长度
        numselected = objVal != 0 ? objVal.split(",").length : objVal;
    }
    //end update by xiu 160601
    return numselected >= need ? true : "请至少选择" + need + "项！";
};
//update-end--Author:zhangguoming  Date:20140826 for：添加 下拉框、combotree 验证
$.Datatype.lessThanInput = function (gets, obj, curform, regxp) {
    gets = $.trim(gets);
    var regexNpn = regxp.nPn;
    var pattern = new RegExp(regexNpn);
    if(!pattern.test(gets)){
        return "请填写整数或两位小数";
    }
    gets = parseInt($.trim(gets));
    var withCompare = obj.attr("with");
    if (!$.isEmptyObject(withCompare) && withCompare != '') {
        withCompare = parseInt($("input[name='" + withCompare + "']").val());
        if(!isNaN(withCompare)){
        	return gets <= withCompare ? true : "不能大于" + withCompare;
        }
    }
};
